package model.loader;

import java.util.ArrayList;

import model.Food;
import model.utils.FileUtils;

import com.thoughtworks.xstream.XStream;

public class XMLInfoLoader {
	
	public ArrayList<Food> loadXmlInfo(String fileName){
		ArrayList<Food> food; 
		String xml = FileUtils.readFile(fileName);
		
		XStream xstream = new XStream();
		xstream.alias("food", Food.class);
		food = (ArrayList<Food>)xstream.fromXML(xml);
		
		return food; 
	}
	
	public ArrayList<Food> loadXmlInfo(){
		return this.loadXmlInfo("calories.xml");
	}
	
	
	public static void main(String[] args){
		ArrayList<Food> food = new XMLInfoLoader().loadXmlInfo("calories.xml");
		for(Food aFood: food){
			System.out.println("Food name: " + aFood.getName() + " calories: " + aFood.getCalories());
		}
	}
}
